$(function () {
	var currYear = (new Date()).getFullYear();	
	var opt={};
	opt.date = {preset : 'date'};
	opt.datetime = {preset : 'datetime'};
	opt.time = {preset : 'time'};
	opt.default = {
		theme: 'android-ics light', //皮肤样式
        display: 'modal', //显示方式 
        mode: 'scroller', //日期选择模式
		dateFormat: 'yyyy-mm-dd',
		lang: 'zh',
		showNow: true,
		nowText: "今天",
        startYear: currYear, //开始年份
        endYear: currYear + 1//结束年份
	};
  	var optDateTime = $.extend(opt['datetime'], opt['default']);
  	var optTime = $.extend(opt['time'], opt['default']);
    $(".appDateTime").mobiscroll(optDateTime).datetime(optDateTime);
    
    
    $('.btn-sub').on('click tap',function(e){
    	console.log('+1s');
        $('.btn-sub').attr('disabled',true);
        setTimeout(function () {
            $('.btn-sub').attr('disabled',false);
        },2000);
        // stu_name: str,
        //     stu_id: str,
        //     stu_phone: str,
        //     parent_phone: str,
        //     start_time: %Y-%m-%d %H:%M,
        //     stop_time: %Y-%m-%d %H:%M,
        //     location: str,
		// 		reason
    	e.preventDefault();
    	var stu_name=$('#stuName').val();
    	var stu_id=$('#stuId').val();
    	var	stu_phone=$('#stuTel').val();
    	var parent_phone=$('#parTel').val();
    	var start_time=$('#start-time').val();
    	var stop_time=$('#end-time').val();
    	var location=$('#goWhere').val();
    	var reason=$('#app-reason').val();
        var reg=/\d{11}/;

    	if(!stu_name||!stu_id||!stu_phone||!parent_phone||!start_time||!stop_time||!location||!reason){
    		$('#alert').html('请假条信息填写不全!');
    		setTimeout(function () {
				$('#alert').html('');
            },3000);
    		return false;
		}
		console.log(reg.test(stu_phone));
		console.log(reg.test(parent_phone));
		if(reg.test(stu_phone)==false || reg.test(parent_phone)==false){
    		alert('请输入正确的电话号码！');
			return false
		}
		$.ajax({
			method:'post',
			url:'',
			data:{
				'stu_name':stu_name,
				'stu_id':stu_id,
				'stu_phone':stu_phone,
				'parent_phone':parent_phone,
				'start_time':start_time,
				'stop_time':stop_time,
				'location':location,
				'reason':reason
			}
		})
			.done(function (data) {
				data = JSON.parse(data);
				if(data.result=='ok'){
                $('#alert').html('申请成功！');
                $('.btn-sub').attr('disabled',true);
                setTimeout(function () {
                   window.location.href='../index'
                },1000);}
                else{
                    $('.btn-sub').attr('disabled',true);
                    $('#alert').html('申请失败！');
                    console.log('error:'+data.error_str);
                    setTimeout(function () {
                        $('#alert').html('');
                        $('.btn-sub').attr('disabled',false);
                    },2000)
				}
            })
			.fail(function () {
                $('#alert').html('error:net');
            });
	     // if (this.promise_.state() === 'pending') {
	   	//  this.promise_.abort();
	   	//  }



	 });
});